var Dao = require('./DAO')
//针对用户的数据表操作的模块对象
var userDAO = {
getAllUsers:function(userId,callback){
  Dao('select * from users where userId=?',
  [userId],function(err,results){
      if(err){
        callback(err,null)
      }else{
        callback(null,results)
      }
  })
},
getgradeId:function(userId,callback){
  Dao('select grade from vip where userId=?',
  [userId],function(err,results){
      if(err){
        callback(err,null)
      }else{
        callback(null,results)
      }
  })
},
getAllevaluateuser:function(orderID,callback){
  Dao('select * from evaluate where orderID=?',[orderID],function(err,results){
      if(err){
        callback(err,null)
      }else{
        callback(null,results)
      }
  })
},
getAllstory:function(userId,callback){
  Dao('select * from storys where userId=?',[userId],function(err,results){
      if(err){
        callback(err,null)
      }else{
        callback(null,results)
      }
  })
},
getAllintegral:function(userId,callback){
  Dao('select * from integral where userId=?',[userId],function(err,results){
      if(err){
        callback(err,null)
      }else{
        callback(null,results)
      }
  })
},
getAllintegift:function(callback){
  Dao('select * from integift',null,function(err,results){
      if(err){
        callback(err,null)
      }else{
        callback(null,results)
      }
  })
},
getAllorders:function(userId,callback){
  Dao('select * from orders where userId=?',[userId],function(err,results){
      if(err){
        callback(err,null)
      }else{
        callback(null,results)
      }
  })
},
// upload: function(users, callback) {
//   console.log(users)
//   Dao('update users set headPic = ? where userId = ?',[users.file,users.userId],function(err,results){
//       if(err){
//           callback(err,null)
//       }else{
//           callback(null,results)
//       }
//   })
// },
upload: function(user, callback) {
  console.log(123)
  console.log(user)
  Dao('update users set headPic = ? where userId = ?',[user.headPic,user.userId1],function(err,results){
    console.log(results)
      if(err){
          callback(err,null)
      }else{
          callback(null,results)
      }
  })
},
changeuser:function(users,callback){
  console.log(222)
  console.log(users)
  Dao('update users set userName = ?  ,sex = ? ,birthday = ? ,address = ? where userId= ?',
  [users.userName,users.sex,users.birthday,users.address,users.userId],function(err,results){
    console.log(results)
    if(err){
      callback(err,null)
    }else{
      callback(null,results)
    }
  })
},
getusertel:function(users,callback){
  Dao('update users set telephone = ?  where userId= ?',
  [users.telephone,users.userId],function(err,results){
    console.log(results)
    if(err){
      callback(err,null)
    }else{
      callback(null,results)
    }
  })
},
getuserpass:function(users,callback){
  Dao('update users set userPassword = ?  where userId= ?',
  [users.newuserpwd,users.userId],function(err,results){
    // console.log(results)
    if(err){
      callback(err,null)
    }else{
      callback(null,results)
    }
  })
},
seluserpass:function(users,callback){
Dao('select * from users where userId = ?',[users.userId],function(err,results){
  // console.log(results)
    if(err){
      callback(err,null)
    }else{
      callback(null,results)
    }
})
},
getAllintecount:function(userId,callback){
  Dao('select sum(integralonce) from integral where userId=?',
  userId,function(err,results){
    if(err){
      callback(err,null)
    }else{
      callback(null,results)
    }
  })
},
getvipcount:function(userId,callback){
  Dao('select sum(investmoney) from investmoney where userId=?',
  userId,function(err,results){
    if(err){
      callback(err,null)
    }else{
      callback(null,results)
    }
  })
},
getinvestmoney:function(invest,callback){
  Dao('insert into investmoney(investmoney,investTime,userID)values(?,now(),?)',
  [invest.investmoney,invest.userID],
  function(err,results){
      if(err){
        callback(err,null)
      }else{
        callback(null,results)
      }
  })
},
}

module.exports = userDAO